<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of welcome
 *
 * @author Obi
 */
class Admin_identitas_website extends MY_Controller {

    function __construct() {
        parent::__construct();

        $cek_admin = $this->session->userdata('cek_admin');
        if (!$cek_admin)
            redirect("admin");
        $this->msetting = new M_setting();
    }

    function index() {
        $data['title'] = 'Data Indentitas Website';
        $data['list'] = $this->msetting->order_by("id")->get();
        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function simpan() {
        $data = $_POST;
        foreach ($data as $key => $val) {
//            print($key);
//            print_r($val);
            if ($key != 'logo_website') {
                $this->msetting->update_spesifik($key, $val);
            }
        }

        $config['overwrite'] = false;
        $config['upload_path'] = './uploads/file/';
        $config['allowed_types'] = 'jpg|png|gif';
        $config['max_size'] = '100000';
        $this->load->library('upload', $config);
        $this->upload->initialize($config);
        $field = 'logo_website';

        if ($this->upload->do_upload($field)) {
            $uploaded = $this->upload->data();
            $file = $uploaded['file_name'];
            $this->msetting->update_spesifik('logo_website', $file);
        }

        redirect("admin_identitas_website");
    }

    function delete_image($image = NULL) {
        $this->msetting->update_spesifik('logo_website', NULL);
        $this->load->helper('file');
        unlink('./uploads/file/' . $image);
        redirect('admin_identitas_website');
    }

}

?>
